package com.learn.test.udf;

import org.apache.flink.table.functions.ScalarFunction;

/**
 * @create: 2023-07-13 16:06
 * @author: Mr.Du
 * --------------
 * @notes:
 **/
public class LongIp extends ScalarFunction {

    public Long eval(String ip) {
        long result = 0L;
        String[] ipSegment = ip.split("\\.");
        //ip格式校验
        if (ipSegment.length != 4) {
            System.out.println("ip 格式错误！！！");
        }
        for (int i =0; i<ipSegment.length; i++) {
            result += Long.parseLong(ipSegment[i].isEmpty() ? "0" : ipSegment[i]) << (8*(3 - i)) ;
        }
        return result;
    }
}
